// import proFetch from "../../../../../public/functions/project-fetch";
import {hrAjax as ajax} from 'src/hrpub/common/utils/utils';
import getMainTableData from "./getMainTableData";
import {toast} from 'nc-lightapp-front';
import getOneAgreementInfo from "./getOneAgreementInfo";
import updateButtonStatus from "./updateButtonStatus";
import handleAllpks from "./handleAllpks"

export default function effectiveAgreementData() {
    const {effectivePks,agreementType,orgVal,pageFlag,editPk} = this.state
    let pksArr = Array.isArray(effectivePks) ? effectivePks : effectivePks.split(',');
    return ajax({
        url: '/nccloud/hrcm/agreement/ReleaseAgreementEffectiveAction.do',
        body:{
            pk_agreements: pksArr
        }
    })
        .then((res) => {
            if (res.success) {
                if (res.success) {
                    if(pageFlag === 'list'){
                        getMainTableData.call(this);
                    }else if(pageFlag === 'card'){
                        let pks = effectivePks.toString();
                        let nextPk = handleAllpks.getNextPk(pks);
                        handleAllpks.remove(pks); // 更新卡片分页主键
                        this.setState({
                            editPk: nextPk,
                        },()=>{
                            handleAllpks.remove(pks); // 更新卡片分页主键
                            getOneAgreementInfo.call(this);
                        });
                    }
                    updateButtonStatus.call(this, orgVal,agreementType);
                    toast({color:'success',content:res.data.msg})
                }
            }
        });
}
